﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using QuanLyTiemVang.DTO;

namespace QuanLyTiemVang.DAO
{
    class KhoanPhiDAO
    {
        private static QUANLYTIEMVANGEntities db = new QUANLYTIEMVANGEntities();

        public static List<KHOANPHI> GetAllKhoanPhi()
        {
            return db.KHOANPHIs.ToList();
        }
        public static KHOANPHI SelectKhoanPhiByMaKhoanPhi(KHOANPHI kp)
        {
            var query = db.KHOANPHIs.Find(kp.MaKhoanPhi);
            if (query != null)
                return query;
            return null;
        }
        public static void Insert(KHOANPHI kp)
        {
            db.KHOANPHIs.Add(kp);
            db.SaveChanges();
        }
        public static void Delete(KHOANPHI kp)
        {
            var query = db.KHOANPHIs.Find(kp.MaKhoanPhi);
            if (query != null)
            {
                db.KHOANPHIs.Remove(query);
                db.SaveChanges();
            }
        }
        public static void Update(KHOANPHI kp)
        {
            var query = db.KHOANPHIs.Find(kp.MaKhoanPhi);
            if (query != null)
            {
                query.TenKhoanPhi = kp.TenKhoanPhi;
                db.SaveChanges();
            }
        }
    }
}
